﻿using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Web;

namespace scmsByAspdNet.cotro.admin {
  /// <summary>
  /// addNews 的摘要说明
  /// </summary>
  public class addNews : IHttpHandler {

    public void ProcessRequest(HttpContext context) {
      context.Response.ContentType = "text/plain";

      //获取数据
      string title = context.Request["title"];
      string detail = context.Request["detail"];
      string img_name = context.Request["img_name"];

      SqlConnection conn = new SqlConnection("Data Source=106.54.69.143;database=scms;uid=sa;pwd=Aspdotnet666");
      conn.Open();

      SqlCommand sql_u = new SqlCommand($"insert into sc_news values('{title}','{detail}','{img_name}',1)", conn);
      int res = sql_u.ExecuteNonQuery();
      conn.Close();
      //返回数据
      context.Response.StatusCode = 200;
      context.Response.Write($"{{\"line\":{res}}}");
    }

    public bool IsReusable {
      get {
        return false;
      }
    }
  }
}